from django.db import models
from .base import BaseModel

class Action(BaseModel):
    """动作模型"""
    battle = models.ForeignKey(
        'Battle',
        on_delete=models.CASCADE,
        related_name='actions',
        verbose_name='所属战斗'
    )
    actor = models.ForeignKey(
        'Character',
        on_delete=models.CASCADE,
        related_name='performed_actions',
        verbose_name='动作执行者'
    )
    
    # 动作类型
    ACTION_TYPES = [
        ('attack', '攻击'),
        ('move', '移动'),
        ('skill', '技能'),
        ('reaction', '反应'),
        ('other', '其他'),
    ]
    action_type = models.CharField(
        max_length=20,
        choices=ACTION_TYPES,
        verbose_name='动作类型'
    )
    
    # 动作数据
    action_data = models.JSONField(verbose_name='动作数据')
    round_number = models.IntegerField(verbose_name='回合数')
    sequence_number = models.IntegerField(verbose_name='序列号')
    
    class Meta:
        verbose_name = '动作'
        verbose_name_plural = '动作'
        ordering = ['round_number', 'sequence_number']

class ActionTarget(BaseModel):
    """动作目标模型"""
    action = models.ForeignKey(
        Action,
        on_delete=models.CASCADE,
        related_name='targets',
        verbose_name='所属动作'
    )
    target = models.ForeignKey(
        'Character',
        on_delete=models.CASCADE,
        related_name='targeted_actions',
        verbose_name='目标角色'
    )
    
    # 效果数据
    effect_data = models.JSONField(verbose_name='效果数据')
    
    class Meta:
        verbose_name = '动作目标'
        verbose_name_plural = '动作目标' 